#!/bin/bash

echo "### igh Ethercat 驱动环境搭建"

# depmod -a

chmod -R +X .

modir -p /lib/modules/4.1.15/

mkdir -p /usr/local/out_igh/
cp -rf ./* /usr/local/out_igh/

cp -rf ./driver/*.ko /lib/modules/4.1.15/
cp -rf ./lib/libethercat.so.1.2.0 /lib/
ln -s /lib/libethercat.so.1.2.0 /lib/libethercat.so
ln -s /lib/libethercat.so.1.2.0 /lib/libethercat.so.1

ln -s /usr/local/out_igh/bin/ethercat /bin/ethercat
ln -s /usr/local/out_igh/etc/init.d/ethercat /etc/init.d/ethercat
ln -s /usr/local/out_igh/etc/ethercat.conf /etc/ethercat.conf
mkdir -p /etc/sysconfig
ln -s /usr/local/out_igh/etc/sysconfig/ethercat /etc/sysconfig/ethercat

ln -s /usr/local/out_igh/sbin/ethercatctl /sbin/ethercatctl


echo KERNEL==\"EtherCAT[0-9]*\", MODE=\"0664\" > /etc/udev/rules.d/99-EtherCAT.rules

# main_devices改成具体的MAC地址
insmod /lib/modules/4.1.15/ec_master.ko main_devices=88:1b:83:dc:f4:c6
insmod /lib/modules/4.1.15/ec_fec_emac.ko

cd /lib/modules/4.1.15/
cp ec_fec_emac.ko generic.ko
cd -

# depmod -a
# modprobe ec_master main_devices=88:1b:83:dc:f4:c6
# modprobe ec_generic

